package com.tangyh.lamp.common.enums;

import com.tangyh.basic.base.BaseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.stream.Stream;

/**
* 登录账号类型
*/
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "AccountType", description = "账号类型-枚举")
public enum AccountType implements BaseEnum {

    /**
     * 租户
     */
    TENANT("租户"),

    /**
     * 租户子账户
     */
    TENANT_SUB_ACCOUNT("租户子账户"),
    /**
     * 园区
     */
    TAX_RESOURCE("园区"),
    /**
     * 销售
     */
    SALESMAN("销售"),
    /**
     * 未认证商户
     */
    NOT_MERCHANT("未认证商户"),
    /**
     * 商户
     */
    MERCHANT("商户"),
    /**
     * 商户子账户
     */
    MERCHANT_SUB_ACCOUNT("商户子账户"),
    /**
     * 个人
     */
    PERSONAL("个人"),
    ;

    @ApiModelProperty(value = "描述")
    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static AccountType match(String val, AccountType def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static AccountType get(String val) {
        return match(val, null);
    }

    public boolean eq(AccountType val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "TENANT,MERCHANT,TAX_RESOURCE,SALESMAN,MERCHANT,PERSONAL", example = "SERVER")
    public String getCode() {
        return this.name();
    }

}
